import { Get, Post, Put, Delete } from '@/utils/request.ts'

export interface CreateMenuDto {
  id?: string | number,
  name: string
  path: string
  component: string
  type: 'menu' | 'button'
  icon?: string
  code?: string
  explain?: string
  // 如果设置父级菜单，则传入 parentId；不传则默认为一级菜单
  parentId?: number
}
export interface UpdateMenuDto {
  name?: string
  path?: string
  component?: string
  type?: 'menu' | 'button'
  icon?: string
  code?: string
  explain?: string
  parentId?: number
}
export interface ListPaginationDto {
  pageNo: number
  pageSize: number
}
export interface MenuDto {
  id: number
  name: string
  path: string
  component: string
  type: 'menu' | 'button'
  icon?: string
  code?: string
  explain?: string
  children: MenuDto[]
  level: number
  disabled?: boolean
}
export interface ListDataDto {
  total: number
  records: MenuDto[]
}

export const createMenuApi = (data: CreateMenuDto) => {
  return Post<CreateMenuDto, never>('/blog/menu', data)
}

export const updateMenuApi = (id: string | number, data: UpdateMenuDto) => {
  return Put<UpdateMenuDto, never>(`/blog/menu/${id}`, data)
}

export const getMenuListApi = (data: ListPaginationDto) => {
  return Get<ListPaginationDto, never>('/blog/menu', data)
}

export const getTypeMenuListApi = () => {
  return Get<never, MenuDto[]>('/blog/menu/tree')
}

export const getIdDetailApi = (id: string | number) => {
  return Get<never, CreateMenuDto>(`/blog/menu/${id}`)
}

export const deleteMenuApi = (id: string | number) => {
  return Delete<never, never>(`/blog/menu/${id}`)
}

export const getRoleMenuApi = (userId: string | number) => {
  return Get<never, string[] | number[]>(`/blog/menu/ids/${userId}`)
}

export const getAllMenuApi = () => {
  return Post<never, never>('/blog/menu/all')
}
